package com.ds.esd.bpm.custom.plugins.attachment;

import com.ds.bpm.client.ActivityInst;
import com.ds.esd.custom.bean.CustomModuleBean;
import com.ds.esd.custom.bean.MethodConfig;
import com.ds.esd.tool.module.EUModule;
import com.ds.esd.tool.ui.component.block.BlockPanelComponent;
import com.ds.esd.tool.ui.component.dialog.DialogComponent;
import com.ds.esd.tool.ui.component.form.FileUploadComponent;
import com.ds.esd.tool.ui.component.form.FileUploadProperties;
import com.ds.esd.tool.ui.enums.Dock;
import com.ds.esd.tool.ui.module.ModuleComponent;
import com.ds.jds.core.esb.EsbUtil;

import java.util.Map;

public class UPLoadView extends ModuleComponent {

    public UPLoadView(EUModule module, MethodConfig methodAPIBean, Map<String, Object> valueMap) {
        euModule = module;
        ActivityInst activityInst = EsbUtil.parExpression("$currActivityInst", ActivityInst.class);
        FileUploadComponent uploadComponent = new FileUploadComponent();
        FileUploadProperties fileUploadProperties = new FileUploadProperties();
        fileUploadProperties.setPrepareFormData(true);
        fileUploadProperties.setDock(Dock.fill);
        fileUploadProperties.setUploadUrl("/custom/bpm/AttachUPLoad");
        uploadComponent.setProperties(fileUploadProperties);
        BlockPanelComponent mainComponent = new BlockPanelComponent<>(Dock.fill, euModule.getName() + "Main");
        mainComponent.addChildren(uploadComponent);
        CustomModuleBean moduleBean = methodAPIBean.getModuleBean();
        this.dialogBean = methodAPIBean.getDialogBean();
        if (dialogBean != null) {
            DialogComponent dialogComponent = this.getDialogComponent();
            dialogComponent.addChildren(mainComponent);
            this.addChildren(dialogComponent);
        } else {
            this.addChildren(mainComponent);
        }
    }

}
